/**
 * 只负责渲染布局
 */

import React from 'react';

import Header from '../components/Header';
import LeftTree from '../../../public/components/LeftTree';
import AddNewPage from '../components/AddNewPage';
import MainTable from '../components/MainTable';
import EmptyPage from '../../../../hrpub/common/components/emptyImg';

import SearchModal from '../components/SearchModal';
import OnlyInfoModal from '../components/OnlyInfoModal';
import ZywhdyModal from '../components/ZywhdyModal';
import ZRCKModal from '../components/ZRCKModal';

import SwitchToDocModal from '../components/SwitchToDocModal';
import FileManager from '../components/Uploader';
import EntryApplyModal from '../components/EntryApplyModal';

// 公共的组件
import SortModal from '../../../public/components/SortModal';
import BatchAddSub from '../../../public/components/BatchAddSub';
import RosterModal from '../../../public/components/RosterModal';
import BatchEditModal from '../../../public/components/BatchEdit/';
import WpsModal from '../../../../hrpub/common/components/wpsPreModel';
import CardView from '../../../../hrpub/common/components/card-view';
import ImportModal from '../components/ImportModal/index';
import {
    base, high, ajax, toast
} from 'nc-lightapp-front';

import language from '../language';

import instant from '../pageIns';

const { PrintOutput } = high;

 
export default class Layout extends React.Component {
    constructor(props) {
        super(props);
    }

    render() {

        const props = this.props;

        const {
            humanResourceOrganizationValue,
            pks,
             page,
            hasSearched,
            pageInfo,
            showTableCheckbox,
            addPageTemplate,
            pageFrom,
            imageData,
            showZRCKModal,
            subTableEditable,
            searchModalVisible,
            zywhdyModalVisible,
            onlyInfoModalVisible,
            queryOid,
            sortModalVisible,
            switchToDocModalVisible,
            currentSelectDepartment,
            uniqueFields,
            batchEditModalVisible,
            selectedRows,
            batchAddSubVisible,
            include_child_depts,
            include_child_orgs,
            include_child_psncl,
            show_all_info,
            rosterModalVisible,
            show_on_job_psn,
            showUploader,
            printData,
            meta,
            editTable,
            form,
            asyncTree,
            MultiInit,
            clickRow,
            mainTableHeight,
            entryApplyModalVisible,
            entryApplyListPks,
            pageHeight,
            photoRequired,
            importModalVisible,
            DragWidthCom,
            contartNewCodeList
        } = props;

        const rosterPks = props.getSelectedField('pk_psnjob', true);
        let darkTheme = document.body.className.includes('c-lightapp-front-black');

        return (
            <div
                className="nc-bill-tree-table entry-mng-page"
                style={{
                    height: 'auto'
                }}
            >
                <Choose>
                    <When condition={page === 'main' || page === 'adjust-sort'}>
                        <div className="main-page">
                            <Header
                                {...this.props}
                                pageInfo={pageInfo}
                                page={page}
                                ref={ref => this.headerRef = ref}
                                updateState={props.updateState}
                                humanResourceOrganizationValue={humanResourceOrganizationValue}
                                getMainTableData={props.getMainTableData}
                                hasSearched={hasSearched}
                                selectedRows={selectedRows}
                                getRef={props.getRef}
                                toEditPage={props.toEditPage}
                                deleteMainTableRow={props.deleteMainTableRow}
                                batchAddSub={props.batchAddSub}
                                include_child_depts={include_child_depts}
                                include_child_orgs={include_child_orgs}
                                goBackToMainPage={props.goBackToMainPage}
                                print={props.print}
                                fileManager={props.fileManager}
                                printOutput={props.printOutput}
                                setButtonStatus2={props.setButtonStatus2}
                                entryApply={props.entryApply}
                                relativeQueryCard={props.relativeQueryCard}
                            />
                            <div className="tree-table entry-mng-page-content"
                                style={{ display: humanResourceOrganizationValue.refpk ? 'block' : 'none' }}
                            >
                                <DragWidthCom
                                    leftDom={
                                        <div
                                            className="left-content"
                                            style={{
                                                height: `${pageHeight - 77}px`,
                                                display: humanResourceOrganizationValue.refpk ? 'block' : 'none',
                                                borderColor: darkTheme ? '#39393f' : '#d7d7d7'
                                            }}
                                        >
                                            <LeftTree
                                                treeType="orgRange"
                                                asyncTree={asyncTree}
                                                onSelect={props.selectTree}
                                                pk_org={humanResourceOrganizationValue.refpk}
                                                treeId="departmentTree"
                                                MultiInit={MultiInit}
                                            />
                                        </div>
                                    }
                                    rightDom={
                                        <div
                                            className="right-content"
                                            ref={ref => instant.rightRef = ref}
                                            style={{
                                                width: humanResourceOrganizationValue.refpk ? 'auto' : '100%',
                                                // marginLeft: humanResourceOrganizationValue.refpk ? '250px' : 0,
                                                height: `${pageHeight - 77}px`,
                                            }}
                                        >
                                            <Choose>
                                                <When condition={humanResourceOrganizationValue.refpk}>
                                                    <MainTable
                                                        {...props}
                                                        updateState={props.updateState}
                                                        handleTableSelect={props.handleTableSelect}
                                                        getMainTableData={props.getMainTableData}
                                                        pageInfo={pageInfo}
                                                        showTableCheckbox={showTableCheckbox}
                                                        toEditPage={props.toEditPage}
                                                        selectAll={props.selectAll}
                                                        page={page}
                                                        pageHeight={pageHeight}
                                                    />
                                                </When>
                                                <Otherwise>
                                                    <EmptyPage
                                                        height={456}
                                                        text={language['hi6007-000191']/** 暂无数据，请先选择人力组织 */}
                                                    />
                                                </Otherwise>
                                            </Choose>
                                        </div>
                                    }
                                    defLeftWid='20%'    // 默认左侧区域宽度，px/百分百
                                    leftMinWid='180px'
                                />
                            </div>
                        </div>
                    </When>
                    <When condition={page === 'add-new'}>
                        <AddNewPage
                            {...props}
                            updateState={props.updateState}
                            addPageTemplate={addPageTemplate}
                            goBackToMainPage={props.goBackToMainPage}
                            pageFrom={pageFrom}
                            contartNewCodeList={contartNewCodeList}
                            ctrtCodesRollBack={props.ctrtCodesRollBack}
                            humanResourceOrganizationValue={humanResourceOrganizationValue}
                            copyRow={props.copyRow}
                            deleteRow={props.deleteRow}
                            addRow={props.addRow}
                            imageData={imageData}
                            cancelEdit={props.cancelEdit}
                            subTableEditable={subTableEditable}
                            getModifyData={props.getModifyData}
                            selectedRows={selectedRows}
                            setButtonStatus2={props.setButtonStatus2}
                            toEditPage={props.toEditPage}
                            setUpLoaderRef={props.setUpLoaderRef}
                            getRef={props.getRef}
                        />
                    </When>
                </Choose>
                <SearchModal
                    {...props}
                    updateState={props.updateState}
                    searchModalVisible={searchModalVisible}
                    getMainTableData={props.getMainTableData}
                />
                <OnlyInfoModal
                    {...props}
                    onlyInfoModalVisible={onlyInfoModalVisible}
                    updateState={props.updateState}
                    queryOid={queryOid}
                    humanResourceOrganizationValue={humanResourceOrganizationValue}
                    currentSelectDepartment={currentSelectDepartment}
                    uniqueFields={uniqueFields}
                    copyRow={props.copyRow}
                    deleteRow={props.deleteRow}
                    pasteRow={props.pasteRow}
                    addRow={props.addRow}
                    processEditPageTemplate={props.processEditPageTemplate}
                    setButtonStatus2={props.setButtonStatus2}
                />
                {/* 职业危害调研模态框 */}
                <ZywhdyModal
                    {...props}
                    zywhdyModalVisible={zywhdyModalVisible}
                    updateState={props.updateState}
                    queryOid={queryOid}
                    humanResourceOrganizationValue={humanResourceOrganizationValue}
                    currentSelectDepartment={currentSelectDepartment}
                    uniqueFields={uniqueFields}
                    copyRow={props.copyRow}
                    deleteRow={props.deleteRow}
                    pasteRow={props.pasteRow}
                    addRow={props.addRow}
                    processEditPageTemplate={props.processEditPageTemplate}
                    setButtonStatus2={props.setButtonStatus2}
                />
                <ZRCKModal
                    {...props}
                    value=''
                    onConfirms={props.zRCKModalOnSure}
                    showZRCKModal={showZRCKModal}
                    pks={pks}
                />
                <SortModal
                    {...props}
                    visible={sortModalVisible}
                    onSure={props.sortModalOnSure}
                    onClose={props.toggleModal('sortModalVisible', false)}
                    templateId="sort"
                    func_type={1}
                />
                <SwitchToDocModal
                    {...props}
                    switchToDocModalVisible={switchToDocModalVisible}
                    updateState={props.updateState}
                    humanResourceOrganizationValue={humanResourceOrganizationValue}
                    getMainTableData={props.getMainTableData}
                />
                <BatchEditModal
                    {...props}
                    batchEditModalVisible={batchEditModalVisible}
                    updateState={props.updateState}
                    ref={ref => this.batchEdit = ref}
                    humanResourceOrganizationValue={humanResourceOrganizationValue}
                    selectedRows={selectedRows}
                    func_type={1}
                />
                <BatchAddSub
                    {...props}
                    meta={meta}
                    editTable={editTable}
                    form={form}
                    visible={batchAddSubVisible}
                    func_type={1}
                    param_str={props.getSelectedField('pk_psnjob').join(',')}
                    pk_org={humanResourceOrganizationValue.refpk}
                    onClose={props.toggleModal('batchAddSubVisible')}
                />
                <RosterModal
                    {...props}
                    orgVal={humanResourceOrganizationValue}
                    queryOid={queryOid}
                    tree_node_id={currentSelectDepartment}
                    include_child_depts={include_child_depts}
                    include_child_orgs={include_child_orgs}
                    include_child_psncl={include_child_psncl}
                    show_all_info={show_all_info}
                    show_on_job_psn={show_on_job_psn}
                    visible={rosterModalVisible}
                    onClose={props.toggleModal('rosterModalVisible', false)}
                    rosterPks={rosterPks && rosterPks.join(',')}
                    func_type={1}
                />
                <If condition={showUploader}>
                    <FileManager
                        json={language}
                        table={editTable}
                        onClose={props.toggleModal('showUploader', false)}
                        clickRow={clickRow}
                    />
                </If>
                <PrintOutput
                    ref={ref => this.printOutputRef = ref}
                    url={'/nccloud/hrhi/psndoc/PsndocTemplatePrintAction.do'}
                    data={printData}
                />
                <EntryApplyModal
                    {...props}
                    updateState={props.updateState}
                    entryApplyModalVisible={entryApplyModalVisible}
                    orgVal={humanResourceOrganizationValue}
                    entryApplyListPks={entryApplyListPks}
                />
                <WpsModal
                    {...props}
                    onRef={props.getWpsRefInstants}
                    appcode={'60071010'}
                    pk_org={humanResourceOrganizationValue}

                />
                <CardView
                    {...props}
                    onRef={props.getRefInstants}
                />
                <ImportModal
                    {...props}
                    visible={importModalVisible}
                    orgVal={humanResourceOrganizationValue}
                    onClose={props.toggleModal('importModalVisible', false)}
                    getMainTableData={props.getMainTableData}
                />

            </div>
        )
    }
}